<template>
  <el-select
    v-model="textbookId"
    placeholder="请选择教材"
    filterable
    clearable
    :disabled="disabled"
    multiple
    collapse-tags
  >
    <el-option
      v-for="dict in textbookList"
      :key="dict.id"
      :label="dict.textbookName"
      :value="dict.id"
    />
  </el-select>
</template>

<script>
import { getTextbookInfoallList } from "@/api/collegebase/textbookInfo";

export default {
  name: "TextBookSelector",
  props: {
    value: {
      type: String,
      default: ""
    },
    disabled: {
      type: Boolean,
      default: false
    }
  }
  ,
  model: {
    prop: 'value',
    event: 'change'
  },
  data() {
    return {
      textbookList: [],
      textbookId: [],
    };
  },

  created() {
    this.getTextbookListData();
  },

  watch: {
    textbookId(value) {
      value = value.join(",");
      this.$emit('change', value)
    },

    value(value) {
      this.textbookId = value ? value.split(",") : [];
    }
  },
  methods: {
    //获取
    async getTextbookListData() {

      const rootRespList = await getTextbookInfoallList();
      this.textbookList = rootRespList.data;
    },

    clear() {
      this.$emit("change", '')
    }


  }

}
</script>

